#!/bin/bash
#httpd
mount /dev/sr0 /media/
rm -rf /etc/yum.repos.d/*
yum=/etc/yum.repos.d/yum.repo
echo "[yum]" > $yum
echo "baseurl=file:///media" >> $yum
echo "enabled=1" >> $yum
echo "gpgcheck=0" >> $yum
systemctl stop firewalld
setenforce 0
yum -y install apr* pcre* cyrus* expat* libdb* openldap-devel
tar -zxf httpd-2.4.25.tar.gz -C /usr/src/
/usr/src/httpd-2.4.25/configure --prefix=/usr/local/httpd
make && make install
ln -s /usr/local/httpd/bin/* /usr/local/bin/
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
sed -i '2i #chkconfig:35 85 21' /etc/init.d/httpd
chkconfig --add httpd
chkconfig httpd on
systemctl start httpd

#mysql
yum -y install ncurses-devel perl* cmake
useradd -M -s /sbin/nologin mysql
tar -zxf mysql-5.6.36.tar.gz -C /usr/src/
cd /usr/src/mysql-5.6.36/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
make && make install
chown mysql:mysql -R /usr/local/mysql
rm -rf /etc/my.cnf
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
ln -s /usr/local/mysql/bin/* /usr/local/bin/
cp /usr/src/mysql-5.6.36/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld 
chkconfig --add mysqld
chkconfig mysqld on
systemctl stop mysqld
systemctl start mysqld
cd
mysqladmin -u root  password "123.com"
mysql -u root -p123.com -e "create database xixi;"
mysql -u root -p123.com -e "create table lzjy.t201(id int,name char(10));"
mysql -u root -p123.com -e "insert into lzjy.t201 values (1,'woshisheng');"

#php
yum -y install zlib-devel xz-devel libxml2-devel
tar -zxf libmcrypt-2.5.8.tar.gz -C /usr/src/
cd /usr/src/libmcrypt-2.5.8/
./configure 
make && make install
cd
ln -s /usr/local/lib/libmcrypt.* /usr/lib
tar -zxf mhash-0.9.9.9.tar.gz -C /usr/src/
/usr/src/mhash-0.9.9.9/configure
cd /usr/src/mhash-0.9.9.9/
./configure 
make && make install
ln -s /usr/local/lib/libmhash* /usr/lib
cd
export LD_LIBRARY_PATH=/usr/local/lib
tar -zxf mcrypt-2.6.8.tar.gz -C /usr/src/
cd /usr/src/mcrypt-2.6.8/
./configure 
make && make install
cd
tar -zxf php-5.5.38.tar.gz -C /usr/src/
cd /usr/src/php-5.5.38/
./configure --prefix=/usr/local/php5 --with-mcrypt --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php5 --enable-mbstring
make && make install
cp /usr/src/php-5.5.38/php.ini-development /usr/local/php5/php.ini
sed -i "s/short_open_tag = Off/short_open_tag = On/g" /usr/local/php5/php.ini
sed -i "s/\;default_charset = \"UTF-8\"/default_charset = \"UTF-8\"/g" /usr/local/php5/php.ini
sed -i "s/DirectoryIndex index.html/DirectoryIndex index.php/g" /usr/local/httpd/conf/httpd.conf
sed -i '$a AddType application/x-httpd-php .php' /usr/local/httpd/conf/httpd.conf
systemctl stop httpd
systemctl start httpd
echo -e '<?php\n
  $conn = mysqli_connect("localhost", "root", "123.com","xixi");\n
  $sql = "select * from xixi.t201";\n
  $result = mysqli_query($conn, $sql);\n
  if (mysqli_num_rows($result) > 0) {\n
    while($row = mysqli_fetch_assoc($result)) {\n
      echo "查询到的数据: " . $row["id"],$row["name"] . "<br>";\n
    }\n
  }\n
?>\n' > /usr/local/httpd/htdocs/index.php
systemctl stop httpd
systemctl start httpd
firefox 127.0.0.1 &
